<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>小豆列表</title>

<link rel="stylesheet" type="text/css" href="${ctx}/resources/media/css/select2_metro.css" />
<link rel="stylesheet" href="${ctx}/resources/media/css/DT_bootstrap.css" />
</head>
<body>
	<div class="row-fluid profile">
		<div class="span12">
			<!--BEGIN TABS-->
			<div class="tabbable tabbable-custom tabbable-full-width">
				<ul class="nav nav-tabs">
					<li class="active"><a href="${ctx}/financing/xiaodou">产品列表</a></li>
					<li><a href="${ctx}/financing/xiaodou/form">添加产品</a></li>
				</ul>
				<div class="tab-content">
                    <div class="alert alert-block alert-warning fade in hide">
                        <button type="button" class="close" data-dismiss="alert"></button>
                        <h4 class="alert-heading">请注意!</h4>
                        <p>
                            你正在执行一个删除操作，你将删除被标记为"<strong style="color:red" class="title">站点标题</strong>"的数据。
                            <br/>请确保你知晓执行该操作的后果，该操作不可恢复！
                        </p>
                        <p>
                            <a class="btn red cconfirm" href="javascript:;">继续删除</a> <a class="btn blue cclose" href="javascript:;">放弃操作</a>
                        </p>

                    </div>
					<div class="tab-pane row-fluid active" id="tab_1_1">
						<div class=" responsive" data-tablet="span12 fix-offset">
							<!-- BEGIN EXAMPLE TABLE PORTLET-->
							<div class="portlet box grey">
								<div class="portlet-title">
									<div class="caption">
										<i class="icon-list"></i>产品列表
									</div>
								</div>
								<div class="portlet-body">
                                    <div class="row-fluid">
                                        <div class="span12 ">
                                            <input type="text" placeholder="标题" id="title" class="m-wrap normal">
                                            <select id="status" style="width:150px">
                                            	<option value="-1">全部</option>
                                            	<option value="0">已审核</option>
                                            	<option value="2">未审核</option>
                                            </select>
                                            <button class="btn blue" onclick="search()"><i class="icon-search"></i> 搜索</button>

                                        </div>
                                    </div>
									<table class="table table-striped table-bordered table-hover " 
										id="dataTable">
										<thead>
											<tr >
												<th>编号</th>
                                                <th style="width:200px">标题</th>
                                                <th>金额</th>
                                                <th>最小投资金额</th>
                                                <th>最大投资金额</th>
                                                <th>收益率</th>
                                                <th>分期数</th>
                                                <th>开始时间</th>
                                                <th>结束时间</th>
                                                <th>状态</th>
												<th style="width:140px">操作</th>
											</tr>
										</thead>
										<tbody>
											
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
					<!--end tab-pane-->
				</div>
			</div>
			<!--END TABS-->
		</div>
	</div>
	<script type="text/javascript" src="${ctx}/resources/media/js/select2.min.js"></script>
	<script type="text/javascript" src="${ctx}/resources/media/js/jquery.dataTables.js"></script>
	<script type="text/javascript" src="${ctx}/resources/media/js/DT_bootstrap.js"></script>
	<script type="text/javascript" src="${ctx}/resources/media/js/form-wizard.js"></script>
	<script type="text/javascript">

        var dt;

		$(function() {
			
			$("select").select2();

            dt = $('#dataTable')
					.dataTable(
							{
								"bLengthChange" : false,
								"bFilter" : true,
								"bInfo" : false,
								"iDisplayLength" : 15,
								"bSort" : false,
								"sDom" : "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
								"sPaginationType" : "bootstrap",
                                "bServerSide":true,
                                "sAjaxSource":"${ctx}/financing/xiaodou/data.json",
								"oLanguage" : {
									"oPaginate" : {
										"sPrevious" : "上一页",
										"sNext" : "下一页"
									}
								},
                                "aoColumns":[
                                    {
                                        "mData":"code"
                                    },{
                                        "mData":"title"
                                    },{
                                        "mData":"amount"
                                    },{
                                        "mData":"minInvestAmount"
                                    },{
                                        "mData":"maxInvestAmount"
                                    },{
                                        "mData":"minProfitRate"
                                    },{
                                        "mData":"term"
                                    },{
                                        "mData":"startTime"
                                    },{
                                        "mData":"endTime"
                                    },{
                                        "mData":null,
                                        "fnRender":function(oObj){
                                        	 var text = "";
                                             if(oObj.aData.status == 0){
                                                 text = "<span class='label label-success'>正常</span>";
                                             } else if(oObj.aData.status == 1){
                                          	   text = "<span class='label label-important'>已删除</span>";
                                             } else if(oObj.aData.status == 2){
                                          	   text = "<span class='label label-warning'>待审核</span>";
                                             } else if(oObj.aData.status == 3){
                                          	   text = "<span class='label label-inverse'>审核失败</span>";
                                             }else if(oObj.aData.status == 6){
                                          	   text = "<span class='label label-important'>已下架</span>";
                                             }
                                             return text;
                                        }
                                    },{
                                        "mData":null,
                                        "fnRender":function(oObj){
                                        	if(oObj.aData.status == 1 || oObj.aData.status == 3){
                                        		return null;
                                        	}
                                        	if(oObj.aData.status == 0  ){
                                        	return ' <a href="javascript:prodDown(\''+oObj.aData.id+'\',\''+oObj.aData.title+'\',6)" class="btn mini black">\
                                           				 <i class="icon-pencil"></i> 下架\
                                            </a>';
                                        	}
                                        	if(oObj.aData.status == 6  ){
                                            	return ' <a href="javascript:prodDown(\''+oObj.aData.id+'\',\''+oObj.aData.title+'\',0)" class="btn mini black">\
                                               				 <i class="icon-pencil"></i> 上架\
                                                </a>';
                                            	}
                                            return ' <a href="${ctx}/financing/xiaodou/update/'+oObj.aData.id+'" class="btn mini black">\
                                                    <i class="icon-pencil"></i> 编辑\
                                            </a>\
                                            <a href="javascript:del(\''+oObj.aData.id+'\',\''+oObj.aData.code+'\',undefined)" class="btn mini red" onClick="del()">\
                                           			 <i class="icon-trash"></i> 删除\
                                    		</a>';
                                        }
                                    }

                                ],
                                "fnServerData":function(sSource,aoData,fnCallback){
                                    for(i in aoData){
                                        if(aoData[i].name == "sSearch")
                                            aoData[i].name = "title";
                                    }

                                    aoData.push({name:'status',value:$("#status").val()});                                   
                                    $.ajax({
                                        "dataType":'json',
                                        "type":'POST',
                                        "url":sSource,
                                        "data":aoData,
                                        "success":fnCallback
                                    });
                                }
							});

			jQuery('#dataTable_wrapper .row-fluid:first').remove();
			jQuery('#dataTable_wrapper .dataTables_length select').addClass(
					"m-wrap small"); // modify table per page dropdown
		});

        function search(){
            dt.fnFilter($("#title").val());     
        }


        function prodDown(id,prodName,title){
        	     if(title==6)
        	    	 title="下架？"
        	    if(title==0)
                	title="上架？"
        	     var txt = "确定要将该产品：'"+prodName+"''"+ title;
        	     
            	alertBasic("提示信息",txt,function(){
            		 $.post("${ctx}/financing/xiaodou/prodDown/"+id,null,function(result){
            	            if(result.success){
            	                search();
            	            }else{
            	            	alert(result.message);
            	            }
            	        },"json") 
            	},1);
            	$("#alert_message_btn_no").show();            
        }
		
        
        function del(id,title,confirm){
            if(confirm == undefined){
                $(".alert-warning").show();
                $("strong.title").html(title);
                $(".cclose").click(function(){
                    $(".alert-warning").hide();
                });
                $(".cconfirm").unbind("click");
                $(".cconfirm").bind("click",function(){
                    del(id,title,1);
                })
            }else{
                $.post("${ctx}/financing/xiaodou/delete/"+id,null,function(result){
                    if(result.success){
                        $(".cclose").click();
                        alertBasic("提示信息","删除成功",null,3);
                        search();
                    }else{
                    	alertBasic("提示信息","删除失败",null,1);
                    }
                },"json")
            }
        }
		
	</script>
</body>
</html>